package Com.HupochuanAdmin.Uil.Do;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
import java.util.regex.Pattern;

import Com.Hupochuan.Uil.Servlet.DoRunServlet;
import Com.Hupochuan.Uil.Util.MemoryPond;
import Com.Hupochuan.Vo.Actor;
import Com.Hupochuan.Vo.Admin;
import Com.Hupochuan.Vo.FlipPanel;
import Com.Hupochuan.Vo.Movie;
import Com.Hupochuan.Vo.MovieActor;
import Com.Hupochuan.Vo.MovieSource;
import Com.Hupochuan.Vo.MovieType;
import Com.HupochuanAdmin.Dal.Tab.ActorTab;
import Com.HupochuanAdmin.Dal.Tab.AdminTab;
import Com.HupochuanAdmin.Dal.Tab.AreaTab;
import Com.HupochuanAdmin.Dal.Tab.DirectorTab;
import Com.HupochuanAdmin.Dal.Tab.FlipPanelTab;
import Com.HupochuanAdmin.Dal.Tab.MovieActorTab;
import Com.HupochuanAdmin.Dal.Tab.MovieSourceTab;
import Com.HupochuanAdmin.Dal.Tab.MovieTab;
import Com.HupochuanAdmin.Dal.Tab.MovieTypeTab;
import Com.HupochuanAdmin.Dal.Tab.PageMovieListTab;
import Com.HupochuanAdmin.Dal.Tab.PageMovieTab;
import Com.HupochuanAdmin.Dal.Tab.TypeTab;
import Com.HupochuanAdmin.Uil.Util.AdminParameter;
import Com.Tester.Tester;

import com.jspsmart.upload.File;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.SmartUpload;

@SuppressWarnings("serial")
public class AjaxDo extends DoRunServlet{
	public void doRun(){
		
		//打印测试
		Tester.print("打印测试 - AjaxDo");
		
		//获得参数
		String action = this.getDoTool().getPara("action");
		
		//打印测试
		Tester.print("打印测试 - action：" + action);
		
		//返回Hashtable
		Hashtable<String,String> returnHash = new Hashtable<String,String>();
		
		//登陆
		if(action.equals("login")){
			this.login(returnHash);
		}
		//验证用户是否登陆
		else if(this.getDoTool().getSess("sessionAdmin") == null){
			//登陆超时
			returnHash.put("stateCode", "overtime");
		}
		//其它请求
		else{
			//注销
			if(action.equals("logout")){
				this.logout(returnHash);
			}
			
			//上传图片
			else if(action.equals("uploadImg")){
				this.uploadImg(returnHash);
			}
			
			//添加电影 信息
			else if(action.equals("addMovieInfo")){
				this.addMovieInfo(returnHash);
			}
			//添加电影 检索电影名
			else if(action.equals("addMovieSeekName")){
				this.addMovieSeekName(returnHash);
			}
			
			//翻盖面板列表 保存
			else if(action.equals("flipPanelListSave")){
				this.flipPanelListSave(returnHash);
			}
			
			//演员列表 保存
			else if(action.equals("actorListSave")){
				this.actorListSave(returnHash);
			}
			//演员列表 添加电影
			else if(action.equals("actorListAddMovieActor")){
				this.actorListAddMovieActor(returnHash);
			}
			//演员列表 更新显示列
			else if(action.equals("actorListUpdateShowCol")){
				this.actorListUpdateShowCol(returnHash);
			}
			//演员列表 删除电影演员
			else if(action.equals("actorListDeleteMovieActor")){
				this.actorListDeleteMovieActor(returnHash);
			}
			//演员列表 删除演员
			else if(action.equals("actorListDeleteActor")){
				this.actorListDeleteActor(returnHash);
			}
			//演员列表 合并演员
			else if(action.equals("actorListMergeActor")){
				this.actorListMergeActor(returnHash);
			}
			
			
			//电影列表 保存
			else if(action.equals("movieListSave")){
				this.movieListSave(returnHash);
			}
			//电影列表 添加电影类型
			else if(action.equals("movieListAddMovieType")){
				this.movieListAddMovieType(returnHash);
			}
			//电影列表 添加电影演员
			else if(action.equals("movieListAddMovieActor")){
				this.movieListAddMovieActor(returnHash);
			}
			//电影列表 添加电影资源
			else if(action.equals("movieListAddMovieSource")){
				this.movieListAddMovieSource(returnHash);
			}
			//电影列表 更新显示列
			else if(action.equals("movieListUpdateShowCol")){
				movieListUpdateShowCol(returnHash);
			}
			//电影列表 删除电影类型
			else if(action.equals("movieListDeleteMovieType")){
				this.movieListDeleteMovieType(returnHash);
			}
			//电影列表 删除电影演员
			else if(action.equals("movieListDeleteMovieActor")){
				this.movieListDeleteMovieActor(returnHash);
			}
			//电影列表 删除电影资源
			else if(action.equals("movieListDeleteMovieSource")){
				this.movieListDeleteMovieSource(returnHash);
			}
			//电影列表 删除电影
			else if(action.equals("movieListDeleteMovie")){
				this.movieListDeleteMovie(returnHash);
			}
			
			
			//重置内存池
			else if(action.equals("resetMemoryPond")){
				this.resetMemoryPond(returnHash);
			}
			//重置修改的静态页面
			else if(action.equals("resetUpdatePage")){
				this.resetUpdatePage(returnHash);
			}
			//重置全部的静态页面
			else if(action.equals("resetAllPage")){
				this.resetAllPage(returnHash);
			}
		}
        
		//发送回客户端页面
		this.getDoTool().sendMsg(returnHash);
	}
	
	/*
	 * 登陆
	 */
	private void login(Hashtable<String,String> returnHash){
		//获得参数
		String userName = this.getDoTool().getPara("userName");
		String userPass = this.getDoTool().getPara("userPass");
		String validateCode = this.getDoTool().getPara("validateCode");
		String SessionValidateCode = (String)this.getDoTool().getSess("SessionValidateCode");
		
		//验证码为空
		if(validateCode.equals("")){
			returnHash.put("stateCode","validateCode_isnull");
			return;
		}
		
		//到这里就可以清除验证码的Session了（用于防止同Session高并发攻击）
		this.getDoTool().removeSess("SessionValidateCode");
		
		//验证码错误
		if(SessionValidateCode == null || !validateCode.toUpperCase().equals(SessionValidateCode.toUpperCase())){
			returnHash.put("stateCode","validateCode_error");
			return;
		}
		
		//获得数据
		Admin admin = AdminTab.getObject().findAdmin(userName, userPass);
		
		//如果没有找到用户
		if(admin == null){
			returnHash.put("stateCode", "userPass_error");
			return;
		}
		
		this.getDoTool().setSess("sessionAdmin", admin);
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 注销
	 */
	private void logout(Hashtable<String,String> returnHash){
		this.getDoTool().removeSess("sessionAdmin");
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 上传 Png图片
	 */
	private void uploadImg(Hashtable<String,String> returnHash){
		try {
			SmartUpload su = new SmartUpload();		
			//初始化
			su.initialize(this.getServletConfig(),this.getDoTool().getRequest(),this.getDoTool().getResponse());
			
			//限制每个文件大小
			su.setMaxFileSize(1024*1024);//1M
			
			//设置允许哪些类型文件上传 
			su.setAllowedFilesList("jpg,png,gif");
			
			//上传
			su.upload();
			
			Files files = su.getFiles();
			
			//得到每一个文件
			File file = files.getFile(0);
			
			//如果用户没有选择文件,继续下个文件的处理
			if(!file.isMissing()){
				String tempImgName = UUID.randomUUID() + "." + file.getFileExt();;
				file.saveAs("/image/temp/" + tempImgName);
				returnHash.put("stateCode", "success");
				returnHash.put("tempImgName",tempImgName);
			}
			else{
				returnHash.put("stateCode", "not_upload");
			}
		} 
		catch (Exception e){
			e.printStackTrace();
			returnHash.put("stateCode", "error");
		}
	}
	
	/*
	 * 添加电影 信息
	 */
	private void addMovieInfo(Hashtable<String,String> returnHash){
		
		//获得参数
		String name = this.getDoTool().getPara("name");
		String byname = this.getDoTool().getPara("byname");
		String tempImgName = this.getDoTool().getPara("tempImgName");
		String type = this.getDoTool().getPara("type");
		String director = this.getDoTool().getPara("director");
		String area = this.getDoTool().getPara("area");
		String releaseDate = this.getDoTool().getPara("releaseDate");
		String baikeUrl = this.getDoTool().getPara("baikeUrl");
		String summary = this.getDoTool().getPara("summary");
		String actor = this.getDoTool().getPara("actor");
		long sourceTypeCount = this.getDoTool().getLongPara("sourceTypeCount");
		
		//要添加的类型Id列表
		List<Long> typeIdList = new Vector<Long>();
		
		//要添加的演员列表
		List<MovieActor> movieActorList = new Vector<MovieActor>();
		
		//要添加的资源列表
		List<MovieSource> movieSourceList = new Vector<MovieSource>();
		
		//验证电影名
		if(name.equals("")){
			returnHash.put("stateCode", "name_is_null");
			return;
		}
		
		long movieId = MovieTab.getObject().findMovieId(name);
		if(movieId != 0){
			returnHash.put("stateCode", "name_exist");
			return;
		}
		
		//验证电影类型
		for(String aType : type.split("[ |,|，|/]")){
			//不处理空字符串
			if(aType.equals("")){
				continue;
			}
			long typeId = TypeTab.getObject().findTypeId(aType);
			typeIdList.add(typeId);
			//类型不存在
			if(typeId == 0){
				returnHash.put("stateCode", "type_not_exist");
				return;
			}
		}
		
		//地区Id
		long areaId = 0;
		//地区名不为空
		if(!area.equals("")){
			//获得电影地区ID
			areaId = AreaTab.getObject().findAreaId(area);
			//地区不存在
			if(areaId == 0){
				returnHash.put("stateCode", "area_not_exist");
				return;
			}
		}
		
		//获得上映时间
		if(!releaseDate.equals("")){
			//转换上映时间格式
			releaseDate = releaseDate.replace("年","-").replace("月","-").replace("日","");
				
			if(!Pattern.matches("\\d{4}-\\d{1,2}-\\d{1,2}",releaseDate)){
				returnHash.put("stateCode", "releaseDate_format_error");
				return;
			}
		}
				
		//导演Id
		long directorId = 0;
		//如果导演不为空
		if(!director.equals("")){
			directorId = DirectorTab.getObject().findDirectorId(director);
			//如果导演不存在 那就先添加一个吧
			if(directorId == 0){
				DirectorTab.getObject().appendData(director);
				directorId = DirectorTab.getObject().findDirectorId(director);
			}
		}
		
		//循环获得电影演员
		for(String actorRow : actor.split("\n")){
			
			String[] actorRowArray = actorRow.split("\t");
			
			//如果此行没有演员信息
			if(actorRow.equals("")){
				continue;
			}
			//演员列表 数据没有用Tab隔开
			else if(actorRowArray.length < 2){
				returnHash.put("stateCode", "actor_format_error");
				return;
			}
			
			//查找演员Id 如果没有找到就添加上
			long actorId = ActorTab.getObject().findActorId(actorRowArray[1]);
			if(actorId == 0){
				ActorTab.getObject().appendData(actorRowArray[1]);
				actorId = ActorTab.getObject().findActorId(actorRowArray[1]);
			}
			
			MovieActor movieActor = new MovieActor();
			movieActor.setActorId(actorId);
			movieActor.setRoleName(actorRowArray[0]);
			movieActorList.add(movieActor);
		}
		
		Tester.print("sourceTypeCount"+sourceTypeCount);
		//循环获得电影资源数据
		for(int i = 0 ; i < sourceTypeCount ; i++){
			long sourceTypeId = this.getDoTool().getLongPara("sourceTypeId_"+i);
			long sourceModeId = this.getDoTool().getLongPara("sourceModeId_"+i);
			String sourceUrl = this.getDoTool().getPara("sourceUrl_"+i);
			
			Tester.print("sourceTypeId"+sourceTypeId);
			Tester.print("sourceUrl"+sourceUrl);
			
			//如果存在资源地址那就添加此资源
			if(!sourceUrl.equals("")){
				MovieSource movieSource = new MovieSource();
				movieSource.setTypeId(sourceTypeId);
				movieSource.setModeId(sourceModeId);
				movieSource.setUrl(sourceUrl);
				movieSourceList.add(movieSource);
			}
		}
		
		//添加电影数据
		MovieTab.getObject().appendData(name,byname,directorId,areaId,releaseDate,baikeUrl,summary);
		
		//获得电影ID
		movieId = MovieTab.getObject().findMovieId(name);
		
		//临时文件名不为空 那就尝试移动文件
		if(!tempImgName.equals("")){
			//移动临时文件到 标准目录中
			StringBuffer newPathBuffer = new StringBuffer();
			newPathBuffer.append("/image/movieLogo/");
			/*
			if(releaseDate.equals("")){
				newPathBuffer.append("null");
			}
			else{
				newPathBuffer.append(releaseDate.split("-")[0]);
			}
			newPathBuffer.append("/");*/
			newPathBuffer.append(String.format("%012d", movieId));//补齐12位ID
			newPathBuffer.append(".");
			newPathBuffer.append(this.getDoTool().getExtName(tempImgName));
			
			//如果移动成功
			if(this.getDoTool().removieTempImg(tempImgName,newPathBuffer.toString())){
				MovieTab.getObject().updateData(newPathBuffer.toString(), movieId);
			}
		}
					
		//循环添加电影类型
		for(long aTypeId : typeIdList){
			MovieTypeTab.getObject().appendData(movieId,aTypeId,0);
		}
		
		//循环添加电影演员
		for(MovieActor movieActor : movieActorList){
			MovieActorTab.getObject().appendData(
				movieId,
				movieActor.getActorId(),
				movieActor.getRoleName(),
				0
			);
		}
		
		//循环添加电影资源
		for(MovieSource movieSource : movieSourceList){
			MovieSourceTab.getObject().appendData(
				movieId, 
				movieSource.getTypeId(), 
				0,
				0, 
				movieSource.getModeId(), 
				movieSource.getUrl(),
				0
			);
		}
		
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 添加电影 检索电影名
	 */
	private void addMovieSeekName(Hashtable<String,String> returnHash){
		//获得参数
		String name = this.getDoTool().getPara("name");
		
		//验证电影名
		if(name.equals("")){
			returnHash.put("stateCode", "name_is_null");
			return;
		}
		
		long movieId = MovieTab.getObject().findMovieId(name);
		if(movieId != 0){
			returnHash.put("stateCode", "name_exist");
			return;
		}
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 翻盖面板列表 保存
	 */
	private void flipPanelListSave(Hashtable<String,String> returnHash){
		
		long pageSize = this.getDoTool().getLongPara("pageSize");;
		
		//要保存的翻盖面板列表
		List<FlipPanel> flipPanelList = new Vector<FlipPanel>();
		
		//循环验证翻盖面板列表数据
		for(int i = 0 ; i < pageSize ; i++){
			//获得参数
			long id = this.getDoTool().getLongPara("id_"+i);
			String name = this.getDoTool().getPara("name_"+i);
			String tempImgName = this.getDoTool().getPara("tempImgName_"+i);
			
			String color = this.getDoTool().getPara("color_"+i);
			String url = this.getDoTool().getPara("url_"+i);
			float weight = this.getDoTool().getFloatPara("weight_"+i);
			
			//ID为空
			if(id == 0){
				break;
			}
			
			//翻盖面板数据模型
			FlipPanel flipPanel = FlipPanelTab.getObject().findFlipPanel(id);
			
			flipPanel.setName(name);
			flipPanel.setTempImgName(tempImgName);
			flipPanel.setColor(color);
			flipPanel.setUrl(url);
			flipPanel.setWeight(weight);
			
			//添加进准备修改的列表
			flipPanelList.add(flipPanel);
		}
		
		//循环修改翻盖面板列表数据
		for(FlipPanel flipPanel : flipPanelList){
			
			//执行修改数据
			FlipPanelTab.getObject().updateData(
				flipPanel.getName(),
				flipPanel.getColor(),
				flipPanel.getUrl(),
				flipPanel.getWeight(),
				flipPanel.getId()
			);
			
			//临时文件名不为空 那就尝试移动文件
			if(!flipPanel.getTempImgName().equals("")){
				//移动临时文件到 标准目录中
				StringBuffer newPathBuffer = new StringBuffer();
				newPathBuffer.append("/image/flipPanel/");
				newPathBuffer.append(String.format("%03d", flipPanel.getId()));//补齐3位ID
				newPathBuffer.append(".");
				newPathBuffer.append(this.getDoTool().getExtName(flipPanel.getTempImgName()));
				
				//如果移动成功
				if(this.getDoTool().removieTempImg(flipPanel.getTempImgName(),newPathBuffer.toString())){
					FlipPanelTab.getObject().updateData(newPathBuffer.toString(), flipPanel.getId());
					//新的文件路径改变了 那就删除以前的
					if(!newPathBuffer.toString().equals(flipPanel.getLogoPath())){
						this.getDoTool().deleteFile(flipPanel.getLogoPath());
					}
				}
			}
		}
		
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 演员列表 保存
	 */
	private void actorListSave(Hashtable<String,String> returnHash){
		
		long pageSize = AdminParameter.getObject().getActorListPageSize();
		Hashtable<String,Boolean> showCol = AdminParameter.getObject().getActorListShowCol();
		
		//要保存的演员列表
		List<Actor> actorList = new Vector<Actor>();
		
		//循环验证演员列表数据
		for(int i = 0 ; i < pageSize ; i++){
			//获得参数
			long id = this.getDoTool().getLongPara("id_"+i);
			String name = this.getDoTool().getPara("name_"+i);
			String tempImgName = this.getDoTool().getPara("tempImgName_"+i);
			String baikeUrl = this.getDoTool().getPara("baikeUrl_"+i);
			String xlwbUrl = this.getDoTool().getPara("xlwbUrl_"+i);
			String txwbUrl = this.getDoTool().getPara("txwbUrl_"+i);
			String bdtbUrl = this.getDoTool().getPara("bdtbUrl_"+i);
			float weight = this.getDoTool().getFloatPara("weight_"+i);
			long movieCount = this.getDoTool().getLongPara("movieCount_"+i);
			
			//ID为空
			if(id == 0){
				break;
			}
			
			//演员数据模型
			Actor actor = ActorTab.getObject().findActor(id);
			List<MovieActor> movieActorList = new Vector<MovieActor>();
			
			//显示演员名
			if(showCol.get("showName")){
				//获得
				long thisNameId = ActorTab.getObject().findActorId(name);
				
				//如果这个演员名所对应的的ID 不是没有 也不是这个演员的ID 那就说明 已经被使用了
				if(thisNameId!=0 && thisNameId!=id){
					returnHash.put("stateCode", "name_exist");
					returnHash.put("name", name);
					return;
				}
				actor.setName(name);
			}
			
			//显示Logo
			if(showCol.get("showLogo")){
				actor.setTempImgName(tempImgName);
			}
			
			//显示数据信息
			if(showCol.get("showBaikeInfo")){
				//显示百科
				if(showCol.get("showBaike")){
					actor.setBaikeUrl(baikeUrl);
				}
				
				//显示新浪微博
				if(showCol.get("showXlwb")){
					actor.setXlwbUrl(xlwbUrl);
				}
				
				//显示腾讯微博
				if(showCol.get("showTxwb")){
					actor.setTxwbUrl(txwbUrl);
				}
				
				//显示百度贴吧
				if(showCol.get("showBdtb")){
					actor.setBdtbUrl(bdtbUrl);
				}
			}
			//显示演员信息
			else if(showCol.get("showMovieInfo")){
				//显示演员
				if(showCol.get("showMovie")){
					//保存电影列表
					for(int j = 0 ; j < movieCount ; j++){
						long movieActorId = this.getDoTool().getLongPara("movieActorId_"+i+"_"+j);
						String movieName = this.getDoTool().getPara("movieName_"+i+"_"+j);
						String roleName = this.getDoTool().getPara("roleName_"+i+"_"+j);
						float roleWeight = this.getDoTool().getFloatPara("roleWeight_"+i+"_"+j);
						
						//验证电影名
						long movieId = MovieTab.getObject().findMovieId(movieName);
						if(movieId == 0){
							returnHash.put("stateCode", "movieName_not_exist");
							returnHash.put("name", movieName);
							return;
						}
						
						MovieActor movieActor = new MovieActor();
						movieActor.setMovieId(movieId);
						movieActor.setRoleName(roleName);
						movieActor.setWeight(roleWeight);
						movieActor.setId(movieActorId);
						
						//添加进准备修改的列表
						movieActorList.add(movieActor);
					}
				}
			}
			
			//显示权重
			if(showCol.get("showWeight")){
				actor.setWeight(weight);
			}
			
			//要修改的电影列表
			actor.setMovieActorList(movieActorList);
			
			//添加进准备修改的列表
			actorList.add(actor);
		}
		
		//循环修改演员列表数据
		for(Actor actor : actorList){
			
			//执行修改数据
			ActorTab.getObject().updateData(
				actor.getName(),
				actor.getBaikeUrl(),
				actor.getXlwbUrl(),
				actor.getTxwbUrl(),
				actor.getBdtbUrl(),
				actor.getWeight(),
				actor.getId()
			);
			
			//临时文件名不为空 那就尝试移动文件
			if(!actor.getTempImgName().equals("")){
				//移动临时文件到 标准目录中
				StringBuffer newPathBuffer = new StringBuffer();
				newPathBuffer.append("/image/actorLogo/");
				newPathBuffer.append(String.format("%012d", actor.getId()));//补齐12位ID
				newPathBuffer.append(".");
				newPathBuffer.append(this.getDoTool().getExtName(actor.getTempImgName()));
				
				//如果移动成功
				if(this.getDoTool().removieTempImg(actor.getTempImgName(),newPathBuffer.toString())){
					ActorTab.getObject().updateData(newPathBuffer.toString(), actor.getId());
					//新的文件路径改变了 那就删除以前的
					if(!newPathBuffer.toString().equals(actor.getLogoPath())){
						this.getDoTool().deleteFile(actor.getLogoPath());
					}
				}
			}
			
			//执行修改演员列表
			for(MovieActor movieActor : actor.getMovieActorList()){
				MovieActorTab.getObject().updateMovieData(
					movieActor.getMovieId(),
					movieActor.getRoleName(),
					movieActor.getWeight(),
					movieActor.getId()
				);
			}
		}
		
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 演员列表 添加电影演员
	 */
	private void actorListAddMovieActor(Hashtable<String,String> returnHash){
		String movieName = this.getDoTool().getPara("movieName");
		long actorId = this.getDoTool().getLongPara("actorId");
		String roleName = this.getDoTool().getPara("roleName");
		float weight = this.getDoTool().getFloatPara("weight");
		
		//验证电影名
		long movieId = MovieTab.getObject().findMovieId(movieName);
		if(movieId == 0){
			returnHash.put("stateCode", "movieName_not_exist");
		}
		else{
			//执行添加 电影演员
			MovieActorTab.getObject().appendData(movieId,actorId,roleName,weight);
			returnHash.put("stateCode", "success");
		}
	}
	
	/*
	 * 演员列表 更新显示列
	 */
	private void actorListUpdateShowCol(Hashtable<String,String> returnHash){
		//显示参数名列表
		List<String> paraNameList = new Vector<String>();
		//显示参数列表
		Hashtable<String,Boolean> showCol = AdminParameter.getObject().getActorListShowCol();
		
		paraNameList.add("showLogo");
		paraNameList.add("showName");
		
		paraNameList.add("showBaikeInfo");
		paraNameList.add("showBaike");
		paraNameList.add("showXlwb");
		paraNameList.add("showTxwb");
		paraNameList.add("showBdtb");
		
		paraNameList.add("showMovieInfo");
		paraNameList.add("showMovie");
		paraNameList.add("showMovieCount");
		paraNameList.add("showWeight");
		paraNameList.add("showCreateTime");
		paraNameList.add("showUpdateTime");
		
		//遍历数组获得参数 并注入内存
		for(String paraName: paraNameList){
			boolean paraValue = this.getDoTool().getBooleanPara(paraName);
			showCol.put(paraName,paraValue);
		}
		
		//获得其余的参数
		long pageSize = this.getDoTool().getLongPara("pageSize");
		String order = this.getDoTool().getPara("order");
		boolean asc =  this.getDoTool().getBooleanPara("asc");
		
		//将参数注入内存
		AdminParameter.getObject().setActorListPageSize(pageSize);
		AdminParameter.getObject().setActorListOrder(order);
		AdminParameter.getObject().setActorListAsc(asc);
		
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 演员列表 删除电影
	 */
	private void actorListDeleteMovieActor(Hashtable<String,String> returnHash){
		long id = this.getDoTool().getLongPara("id");
		//执行删除 电影演员
		MovieActorTab.getObject().deleteData(id);
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 演员列表 删除演员
	 */
	private void actorListDeleteActor(Hashtable<String,String> returnHash){
		long count = this.getDoTool().getLongPara("count");
		for(int i = 0 ; i < count ; i++){
			long id = this.getDoTool().getLongPara("id_"+i);
			
			//执行删除 电影演员列表
			MovieActorTab.getObject().deleteDataByActorId(id);
			
			//获得演员对象
			Actor actor = ActorTab.getObject().findActor(id);
			
			//删除演员照片
			this.getDoTool().deleteFile(actor.getLogoPath());
			
			//执行删除 演员
			ActorTab.getObject().deleteData(id);
		}
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 演员列表 合并演员
	 */
	private void actorListMergeActor(Hashtable<String,String> returnHash){
		long count = this.getDoTool().getLongPara("count");
		long holdId = this.getDoTool().getLongPara("holdId");
		
		for(int i = 0 ; i < count ; i++){
			long id = this.getDoTool().getLongPara("id_"+i);
			if(id != holdId){
				//执行更新 电影演员列表
				MovieActorTab.getObject().updateData(holdId, id);
				
				//获得演员对象
				Actor actor = ActorTab.getObject().findActor(id);
				
				//删除演员照片
				this.getDoTool().deleteFile(actor.getLogoPath());
				
				//执行删除 演员
				ActorTab.getObject().deleteData(id);
			}
		}
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 保存
	 */
	private void movieListSave(Hashtable<String,String> returnHash){	
		long pageSize = AdminParameter.getObject().getMovieListPageSize();
		Hashtable<String,Boolean> showCol = AdminParameter.getObject().getMovieListShowCol();
		
		//要保存的电影列表
		List<Movie> movieList = new Vector<Movie>();
		
		//循环检验电影列表数据
		for(int i = 0 ; i < pageSize ; i++){
			
			//获得参数
			long id = this.getDoTool().getLongPara("id_"+i);
			String name = this.getDoTool().getPara("name_"+i);
			String byname = this.getDoTool().getPara("byname_"+i);
			String tempImgName = this.getDoTool().getPara("tempImgName_"+i);
			String baikeUrl = this.getDoTool().getPara("baikeUrl_"+i);
			String area = this.getDoTool().getPara("area_"+i);
			String director = this.getDoTool().getPara("director_"+i);
			String summary = this.getDoTool().getPara("summary_"+i);
			String releaseDate = this.getDoTool().getPara("releaseDate_"+i);
			float weight = this.getDoTool().getFloatPara("weight_"+i);
			long typeCount = this.getDoTool().getLongPara("typeCount_"+i);
			long actorCount = this.getDoTool().getLongPara("actorCount_"+i);
			long sourceCount = this.getDoTool().getLongPara("sourceCount_"+i);
			
			//ID为空
			if(id == 0){
				break;
			}
			
			//电影数据模型
			Movie movie = MovieTab.getObject().findMovie(id);
			List<MovieType> movieTypeList = new Vector<MovieType>();
			List<MovieActor> movieActorList = new Vector<MovieActor>();
			List<MovieSource> movieSourceList = new Vector<MovieSource>();
			
			//显示电影名
			if(showCol.get("showName")){
				//获得
				long thisNameId = MovieTab.getObject().findMovieId(name);
				
				//如果这个电影名所对应的的ID 不是没有 也不是这个电影的ID 那就说明 已经被使用了
				if(thisNameId!=0 && thisNameId!=id){
					returnHash.put("stateCode", "name_exist");
					returnHash.put("name", name);
					return;
				}
				movie.setName(name);
				movie.setByname(byname);
			}
			
			//显示Logo
			if(showCol.get("showLogo")){
				movie.setTempImgName(tempImgName);
			}
			//显示数据信息
			if(showCol.get("showBaikeInfo")){
				//显示百科
				if(showCol.get("showBaike")){
					movie.setBaikeUrl(baikeUrl);
				}
				
				//显示地区
				if(showCol.get("showArea")){
					long areaId = 0;
					if(!area.equals("")){
						areaId = AreaTab.getObject().findAreaId(area);
						
						//地区不存在
						if(areaId == 0){
							returnHash.put("stateCode", "area_not_exist");
							returnHash.put("area", area);
							return;
						}
					}
					movie.setAreaId(areaId);
				}
				
				//显示类型
				if(showCol.get("showType")){
					//保存类型列表
					for(int j = 0 ; j < typeCount ; j++){
						long movieTypeId = this.getDoTool().getLongPara("movieTypeId_"+i+"_"+j);
						long typeId = this.getDoTool().getLongPara("typeId_"+i+"_"+j);
						float typeWeight = this.getDoTool().getFloatPara("typeWeight_"+i+"_"+j);
						
						MovieType movieType = new MovieType();
						movieType.setTypeId(typeId);
						movieType.setWeight(typeWeight);
						movieType.setId(movieTypeId);
						
						//添加进准备修改的列表
						movieTypeList.add(movieType);
					}
				}
			}
			//显示导演信息
			if(showCol.get("showDirectorInfo")){
				//显示导演
				if(showCol.get("showDirector")){
					long directorId = 0;
					if(!director.equals("")){
						directorId = DirectorTab.getObject().findDirectorId(director);
						
						//如果导演不存在 那就先添加一个吧
						if(directorId == 0){
							DirectorTab.getObject().appendData(director);
							directorId = DirectorTab.getObject().findDirectorId(director);
						}
					}
					movie.setDirectorId(directorId);
				}
				
				//显示演员
				if(showCol.get("showActor")){
					//保存演员列表
					for(int j = 0 ; j < actorCount ; j++){
						long movieActorId = this.getDoTool().getLongPara("movieActorId_"+i+"_"+j);
						String actorName = this.getDoTool().getPara("actorName_"+i+"_"+j);
						String roleName = this.getDoTool().getPara("roleName_"+i+"_"+j);
						float roleWeight = this.getDoTool().getFloatPara("roleWeight_"+i+"_"+j);
						
						//查找演员Id 如果没有找到就添加上
						long actorId = ActorTab.getObject().findActorId(actorName);
						if(actorId == 0){
							ActorTab.getObject().appendData(actorName);
							actorId = ActorTab.getObject().findActorId(actorName);
						}
						
						MovieActor movieActor = new MovieActor();
						movieActor.setActorId(actorId);
						movieActor.setRoleName(roleName);
						movieActor.setWeight(roleWeight);
						movieActor.setId(movieActorId);
						
						//添加进准备修改的列表
						movieActorList.add(movieActor);
					}
				}
			}
			//显示简介信息
			if(showCol.get("showSummaryInfo")){
				//显示简介
				if(showCol.get("showSummary")){
					movie.setSummary(summary);
				}
			}
			
			//显示简介信息
			if(showCol.get("showSummaryInfo")){
				//显示简介
				if(showCol.get("showSummary")){
					movie.setSummary(summary);
				}
				
				//显示上映时间
				if(showCol.get("showReleaseDate")){
					//获得上映时间
					if(!releaseDate.equals("")){
						//转换上映时间格式
						releaseDate = releaseDate.replace("年","-").replace("月","-").replace("日","");
						
						if(!Pattern.matches("\\d{4}-\\d{1,2}-\\d{1,2}",releaseDate)){
							returnHash.put("stateCode", "releaseDate_format_error");
							returnHash.put("releaseDate", releaseDate);
							return;
						}
					}
					
					try {
						Date sqlDate = new Date(new SimpleDateFormat("yyyy-MM-dd").parse(releaseDate).getTime());
						movie.setReleaseDate(sqlDate);
					} 
					catch (ParseException e) {
						movie.setReleaseDate(null);
						e.printStackTrace();
					}
				}
			}
			
			//显示资源信息
			if(showCol.get("showSourceInfo")){
				//显示资源
				if(showCol.get("showSource")){
					
					Tester.print("sourceCount:"+sourceCount);
					//保存演员列表
					for(int j = 0 ; j < sourceCount ; j++){
						long movieSourceId = this.getDoTool().getLongPara("movieSourceId_"+i+"_"+j);
						long sourceTypeId = this.getDoTool().getLongPara("sourceTypeId_"+i+"_"+j);
						long sourceLanguageId = this.getDoTool().getLongPara("sourceLanguageId_"+i+"_"+j);
						long sourceSubtitleId = this.getDoTool().getLongPara("sourceSubtitleId_"+i+"_"+j);
						long sourceModeId = this.getDoTool().getLongPara("sourceModeId_"+i+"_"+j);
						String sourceUrl = this.getDoTool().getPara("sourceUrl_"+i+"_"+j);
						float sourceWeight = this.getDoTool().getFloatPara("sourceWeight_"+i+"_"+j);
						
						MovieSource movieSource = new MovieSource();
						movieSource.setTypeId(sourceTypeId);
						movieSource.setLanguageId(sourceLanguageId);
						movieSource.setSubtitleId(sourceSubtitleId);
						movieSource.setModeId(sourceModeId);
						movieSource.setUrl(sourceUrl);
						movieSource.setWeight(sourceWeight);
						movieSource.setId(movieSourceId);
						
						//添加进准备修改的列表
						movieSourceList.add(movieSource);
					}
				}
			}
			
			//显示权重
			if(showCol.get("showWeight")){
				movie.setWeight(weight);
			}
			
			//要修改的类型列表
			movie.setMovieTypeList(movieTypeList);
			
			//要修改的演员列表
			movie.setMovieActorList(movieActorList);
			
			//要修改的资源列表
			movie.setMovieSourceList(movieSourceList);
			
			//添加进准备修改的列表
			movieList.add(movie);
		}
		
		//循环修改演员列表数据
		for(Movie movie : movieList){
			
			String releaseDateString = movie.getReleaseDate() == null ? "" : movie.getReleaseDate().toString();
			//执行修改数据
			MovieTab.getObject().updateData(
				movie.getName(), 
				movie.getByname(), 
				movie.getDirectorId(),
				movie.getAreaId(),
				releaseDateString,
				movie.getBaikeUrl(),
				movie.getSummary(),
				movie.getWeight(),
				movie.getId()
			);
			
			//临时文件名不为空 那就尝试移动文件
			if(!movie.getTempImgName().equals("")){
				//移动临时文件到 标准目录中
				StringBuffer newPathBuffer = new StringBuffer();
				newPathBuffer.append("/image/movieLogo/");/*
				if(releaseDateString.equals("")){
					newPathBuffer.append("null");
				}
				else{
					newPathBuffer.append(releaseDateString.split("-")[0]);
				}
				newPathBuffer.append("/");*/
				newPathBuffer.append(String.format("%012d", movie.getId()));
				newPathBuffer.append(".");
				newPathBuffer.append(this.getDoTool().getExtName(movie.getTempImgName()));
				
				//如果移动成功
				if(this.getDoTool().removieTempImg(movie.getTempImgName(),newPathBuffer.toString())){
					MovieTab.getObject().updateData(newPathBuffer.toString(), movie.getId());
					//新的文件路径改变了 那就删除以前的
					if(!newPathBuffer.toString().equals(movie.getLogoPath())){
						this.getDoTool().deleteFile(movie.getLogoPath());
					}
				}
			}
			
			//执行修改类型列表
			for(MovieType movieType : movie.getMovieTypeList()){
				MovieTypeTab.getObject().updateData(
					movieType.getTypeId(),
					movieType.getWeight(),
					movieType.getId()
				);
			}
			
			//执行修改演员列表
			for(MovieActor movieActor : movie.getMovieActorList()){
				MovieActorTab.getObject().updateActorData(
					movieActor.getActorId(),
					movieActor.getRoleName(),
					movieActor.getWeight(),
					movieActor.getId()
				);
			}
			
			//执行修改资源列表
			for(MovieSource movieSource : movie.getMovieSourceList()){
				MovieSourceTab.getObject().updateData(
					movieSource.getTypeId(),
					movieSource.getLanguageId(),
					movieSource.getSubtitleId(),
					movieSource.getModeId(),
					movieSource.getUrl(),
					movieSource.getWeight(),
					movieSource.getId()
				);
			}
			
		}
		
		returnHash.put("stateCode", "success");
	}
	
	/*
	 * 电影列表 添加电影类型
	 */
	private void movieListAddMovieType(Hashtable<String,String> returnHash){
		
		long movieId = this.getDoTool().getLongPara("movieId");
		long typeId = this.getDoTool().getLongPara("typeId");
		float weight = this.getDoTool().getFloatPara("weight");
		
		//执行添加 电影类型
		MovieTypeTab.getObject().appendData(movieId, typeId,weight);
		
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 添加电影演员
	 */
	private void movieListAddMovieActor(Hashtable<String,String> returnHash){
		
		long movieId = this.getDoTool().getLongPara("movieId");
		String actorName = this.getDoTool().getPara("actorName");
		String roleName = this.getDoTool().getPara("roleName");
		float weight = this.getDoTool().getFloatPara("weight");
		
		//查找演员Id 如果没有找到就添加上
		long actorId = ActorTab.getObject().findActorId(actorName);
		if(actorId == 0){
			ActorTab.getObject().appendData(actorName);
			actorId = ActorTab.getObject().findActorId(actorName);
		}
		
		//执行添加 电影演员
		MovieActorTab.getObject().appendData(movieId,actorId,roleName,weight);
		
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 添加电影资源
	 */
	private void movieListAddMovieSource(Hashtable<String,String> returnHash){
		long movieId = this.getDoTool().getLongPara("movieId");
		long typeId = this.getDoTool().getLongPara("typeId");
		long languageId = this.getDoTool().getLongPara("languageId");
		long subtitleId = this.getDoTool().getLongPara("subtitleId");
		long modeId = this.getDoTool().getLongPara("modeId");
		String url= this.getDoTool().getPara("url");
		float weight = this.getDoTool().getFloatPara("weight");
		
		//执行添加 电影资源
		MovieSourceTab.getObject().appendData(movieId,typeId,languageId,subtitleId,modeId,url,weight);
		
		returnHash.put("stateCode","success");
	}
	
	
	/*
	 * 电影列表 更新显示列
	 */
	private void movieListUpdateShowCol(Hashtable<String,String> returnHash){
		//显示参数名列表
		List<String> paraNameList = new Vector<String>();
		//显示参数列表
		Hashtable<String,Boolean> showCol = AdminParameter.getObject().getMovieListShowCol();
		
		paraNameList.add("showLogo");
		paraNameList.add("showName");
		
		paraNameList.add("showBaikeInfo");
		paraNameList.add("showBaike");
		paraNameList.add("showArea");
		paraNameList.add("showType");
		paraNameList.add("showTypeCount");
		
		paraNameList.add("showDirectorInfo");
		paraNameList.add("showDirector");
		paraNameList.add("showActor");
		paraNameList.add("showActorCount");
		
		paraNameList.add("showSummaryInfo");
		paraNameList.add("showSummary");
		paraNameList.add("showReleaseDate");
		
		paraNameList.add("showSourceInfo");
		paraNameList.add("showSource");
		paraNameList.add("showSourceCount");
		
		paraNameList.add("showWeight");
		paraNameList.add("showCreateTime");
		paraNameList.add("showUpdateTime");
		
		//遍历数组获得参数 并注入内存
		for(String paraName: paraNameList){
			boolean paraValue = this.getDoTool().getBooleanPara(paraName);
			showCol.put(paraName,paraValue);
		}
		
		//获得其余的参数
		long pageSize = this.getDoTool().getLongPara("pageSize");
		String order = this.getDoTool().getPara("order");
		boolean asc =  this.getDoTool().getBooleanPara("asc");
		
		//将参数注入内存
		AdminParameter.getObject().setMovieListPageSize(pageSize);
		AdminParameter.getObject().setMovieListOrder(order);
		AdminParameter.getObject().setMovieListAsc(asc);
		
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 删除电影类型
	 */
	private void movieListDeleteMovieType(Hashtable<String,String> returnHash){
		long id = this.getDoTool().getLongPara("id");
		//执行删除 电影类型
		MovieTypeTab.getObject().deleteData(id);
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 删除电影演员
	 */
	private void movieListDeleteMovieActor(Hashtable<String,String> returnHash){
		long id = this.getDoTool().getLongPara("id");
		//执行删除 电影演员
		MovieActorTab.getObject().deleteData(id);
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 删除电影资源
	 */
	private void movieListDeleteMovieSource(Hashtable<String,String> returnHash){
		long id = this.getDoTool().getLongPara("id");
		//执行删除 电影资源
		MovieSourceTab.getObject().deleteData(id);
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 电影列表 删除电影
	 */
	private void movieListDeleteMovie(Hashtable<String,String> returnHash){
		long count = this.getDoTool().getLongPara("count");
		for(int i = 0 ; i < count ; i++){
			long id = this.getDoTool().getLongPara("id_"+i);
			
			//执行删除 电影类型列表
			MovieTypeTab.getObject().deleteDataByMovieId(id);
			
			//执行删除 电影演员列表
			MovieActorTab.getObject().deleteDataByMovieId(id);
			
			//执行删除 电影资源列表
			MovieSourceTab.getObject().deleteDataByMovieId(id);
			
			//获得电影对象
			Movie movie = MovieTab.getObject().findMovie(id);
			
			//删除电影海报
			this.getDoTool().deleteFile(movie.getLogoPath());
			
			//执行删除 电影
			MovieTab.getObject().deleteData(id);
		}
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 清理冗余数据
	
	private Hashtable<String,String> clearRedundance(){
		//返回Hashtable
		Hashtable<String,String> returnHash = new Hashtable<String,String>();
		
		String type = this.getDoTool().getPara("type");
		
		//类型是 电影海报 或 演员照片
		if(type.equals("movieLogo") || type.equals("actorLogo")){
		
			String logoUrl = this.getDoTool().getRootPath() + "/image/"+type+"/";
			File logoDirectory = new File(logoUrl);
			
			String[] fileNameList = logoDirectory.list();
			
			long deleteCount = 0;
			long lengthCount = 0;
			for(String fileName : fileNameList){
				//logo使用次数
				long logoUseCount = 1;
				
				if(type.equals("movieLogo")){
					logoUseCount = MovieTab.getObject().findMovieCount(fileName);
				}
				else if(type.equals("actorLogo")){
					logoUseCount = ActorTab.getObject().findActorCount(fileName);
				}
				//如果这张图片没有使用过 那就删除吧
				if(logoUseCount == 0){
					File logoFile = new File(logoUrl + fileName);
					lengthCount += logoFile.length();
					deleteCount ++;
					logoFile.delete();
				}
			}
			returnHash.put("stateCode", "success");
			returnHash.put("deleteCount", ""+deleteCount);
			returnHash.put("lengthCount", ""+lengthCount);
		}
		
		return returnHash;
	} */
	
	/*
	 * 重置内存池
	 */
	private void resetMemoryPond(Hashtable<String,String> returnHash){
		MemoryPond.reset();
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 重置修改的静态页面
	 */
	private void resetUpdatePage(Hashtable<String,String> returnHash){
		returnHash.put("stateCode","success");
	}
	
	/*
	 * 重置全部的静态页面
	 */
	private void resetAllPage(Hashtable<String,String> returnHash){
		//更新全部电影页面为需要更新状态
		PageMovieTab.getObject().updateIsUpdateByAll();
		
		//更新全部电影列表页面为需要更新状态
		PageMovieListTab.getObject().updateIsUpdateByAll();
		
		returnHash.put("stateCode","success");
	}
}
